package com.qf.xiangqin.servlet;

import com.qf.xiangqin.dao.UserDao;
import com.qf.xiangqin.entity.User;



import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/api/user/findpass")
public class UserFindServlet extends HttpServlet {
    private UserDao dao=new UserDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取参数
        //2.查询账号是否存在
        User user=dao.selectByName(req.getParameter("username"));
        //3.存在 修改密码
        if(user!=null){
            //存在账号  修改密码
            if(dao.updatePassword(user.getId(),req.getParameter("password"))>0){
                //成功
                resp.getWriter().println(200);
            }else{
                //失败
                resp.getWriter().println(400);
            }
        }else {
            //不存在
            resp.getWriter().println(300);
        }
        //4.结果 返回  1.成功 2.账号不存在 3.失败
    }
}
